package com.logic.modular.game.battle.process.domain;

import cn.hutool.extra.spring.SpringUtil;
import com.logic.comment.util.RedisUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 战斗信息
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BattleInfo {
    private Long battleId;// 战斗id
    private Long cityId;// 城市id
    private Long playerId1;// 玩家1 攻击方
    private Long playerId0;// 玩家0 防守方
    private PreparationStageInfo preparationStageInfo;
    public Map<Integer, BattleRoundInfo> battleRound = new HashMap<>();// key: 回合数

    public void saveCache() {
        RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
        redisUtils.set("battleInfo:" + battleId, this, 60, TimeUnit.MINUTES);
    }

    public static BattleInfo selectCache(Long battleId) {
        RedisUtils redisUtils = SpringUtil.getBean(RedisUtils.class);
        return (BattleInfo) redisUtils.get("battleInfo:" + battleId);
    }
}
